package com.onec.service.route.service.base.impl;

import com.onec.service.api.dto.request.route.RouteReq;
import com.onec.service.api.enums.error.RouteErrorEnum;
import com.onec.service.api.exception.RouteException;
import com.onec.service.route.entity.TradeRuleInfo;
import com.onec.service.route.service.base.BaseTradeConfigDefaultService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author onec
 * @Cacheable 一般应用在service中：
 * 代理商业务逻辑处理：用户名中是否包含敏感信息：
 */
@Slf4j
@Service("AGENT_NAME_LIMIT_SERVICE")
public class AgentLimitInfoNameServiceImpl extends BaseTradeConfigDefaultService {


    /**
     * 验证是否包含配置的敏感信息：
     *
     * @param onlineParam   bizContent
     * @param tradeRuleInfo
     * @return
     */
    @Override
    public boolean beforeExecute(RouteReq onlineParam, TradeRuleInfo tradeRuleInfo) {

        String[] sensitiveMsg = tradeRuleInfo.getValue().split(",");
        log.info("上送明文：{}，配置敏感信息：{}", onlineParam.getMerchantName(), sensitiveMsg);
        for (String sensitiveValue : sensitiveMsg) {
            if (onlineParam.getMerchantName().contains(sensitiveValue)) {
                throw new RouteException(RouteErrorEnum.SENSITIVE_MERCHANT, sensitiveValue);
            }
        }
        return false;
    }
}
